package com.dx.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @version 1.0
 * @author: YU.TAN
 * @date: 2023/7/16 15:55
 * @Description:
 * @EnableSwagger2 注解， 标记项目启用 Swagger API 接口文档。
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket createRestApi() {
        //创建Docket
        //文档类型 使用Swagger2
        return new Docket(DocumentationType.SWAGGER_2)
                //设置API信息
                .apiInfo(this.apiInfo())
                // 扫描 Controller 包路径，获得 API 接口
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.dx"))
                .paths(PathSelectors.any())
                // 构建出 Docket 对象
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("测试接口文档示例")
                .description("我是一段描述信息")
                .version("1.0.0")
                .contact(new Contact("YU.TAN", "www.yutan.com", "yutan@gmail.com"))
                .build();
    }
}
